package com.ruoyi.business.controller;

import com.ruoyi.business.domain.TbGoodsCount;
import com.ruoyi.business.domain.TbGoodsDict;
import com.ruoyi.business.service.ITbGoodsOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * ClassName:TbGoodsCountController
 * Description:
 *
 * @date:2021/4/25 10:09
 * @author: tangk
 */
@Controller
@RequestMapping("/business/count")
public class TbGoodsCountController extends BaseController {

    private String prefix = "business/count";

    @Autowired
    private ITbGoodsOrderService tbGoodsOrderService;

    @RequiresPermissions("business:count:view")
    @GetMapping()
    public String count(ModelMap mmap) {
        List<String> list = tbGoodsOrderService.selectTbGoodsAccountMonth();
        mmap.addAttribute("accountMonth", list);
        return prefix + "/count";
    }

    @RequiresPermissions("business:count:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbGoodsCount tbGoodsCount) {
        String accountMonth = tbGoodsCount.getAccountMonth();
        if (accountMonth != null && !accountMonth.equals("")) {
            startPage();
            List<TbGoodsCount> list = tbGoodsOrderService.selectTbGoodsCountList(tbGoodsCount);
            List<TbGoodsCount> month = tbGoodsOrderService.selectTbGoodsCount(tbGoodsCount);
            TableDataInfo tableDataInfo = getDataTable(list);
            ((List<TbGoodsCount>) tableDataInfo.getRows()).add(0,month.get(0));
            return tableDataInfo;
        }else {
            startPage();
            List<TbGoodsCount> month = tbGoodsOrderService.selectTbGoodsCount(tbGoodsCount);
            TableDataInfo tableDataInfo = getDataTable(month);
            return tableDataInfo;
        }
    }
}
